OK = 0

VCODE_ERROR = 1000
LOGIN_REQUIRE = 1001
USER_NOT_EXIST = 1002
PROFILE_ERROR = 1003


class LogicError(Exception):
    '''逻辑异常类'''
    code = 0

    def __str__(self) -> str:
        return self.__class__.__name__


def generate_logic_error(name, code):
    base_cls = (LogicError,)
    return type(name, base_cls,{'code':code})


OK = generate_logic_error('OK', 200)

VcodeError = generate_logic_error('VcodeError', 1000)
VcodeExist = generate_logic_error('VcodeError', 1001)
LoginRequire = generate_logic_error('LoginRequire', 1002)
UserNotExist = generate_logic_error('UserNotExist', 1003)
ProfileError = generate_logic_error('ProfileError', 1004)
NotHasPerm = generate_logic_error('NotHasPerm', 1005)

ParamsError = generate_logic_error('ParamsError', 400) # 参数错误 
ParamsExist = generate_logic_error('ParamsExist', 401) # 参数已存在
ParamsNotExist = generate_logic_error('ParamsNotExist', 402) # 参数不存在

DBError = generate_logic_error('DBError', 500) # 数据库错误
